<?php

namespace App\Http\Controllers\Admin;

use App\Models\Node;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Validation\ValidationException;

class NodeController extends Controller
{
    //节点列表
    public function index()
    {
        $model = new Node;
        $data = $model->getAllList();

        return view('admin.node.index', compact('data'));
    }


    public function create()
    {
        $data = Node::where('pid', 0)->get();
        return view('admin.node.create', compact('data'));
    }


    public function store(Request $request)
    {
        try {
            $this->validate($request, [
                'pid' => 'required',
                'name' => 'required',
              //  'route_name' => 'required',
                'is_menu' => 'required'
            ]);

        } catch (ValidationException $e) {
            return ['status' => 1000, 'msg' => '验证失败'];
        }
        Node::create($request->only(['pid', 'name', 'route_name', 'is_menu']));
        return ['status' => 0, 'msg' => '添加节点成功'];
    }


    public function show(Node $node)
    {
        //
    }


    public function edit(Node $node)
    {
        //
    }


    public function update(Request $request, Node $node)
    {
        //
    }


    public function destroy(Node $node)
    {
        //
    }
}
